/*
 * FAtoms.h
 *
 *  Created on: May 13, 2012
 *      Author: marchi
 */

#ifndef FATOMS_H_
#define FATOMS_H_
#include <string>
#include "Atoms.h"
#include "HeaderTrj.h"
#include "typedefs.h"
#include "MyUtilClass.h"
#include "nrjac.h"
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <algorithm>

using namespace DVECT;
using namespace std;
typedef float Real;
class FAtoms: public Atoms {
protected:
	bool firsttime;
	void ReadaStep(FstreamC * );
	void ReadaStep(FstreamF * );
	void ReadaStep(std::ifstream &);
	void ReadaStepF(std::ifstream &);
	void moveOffset(FstreamC *);
	void moveOffset(FstreamF *);
	void moveOffset(std::ifstream &);
	void WriteaStep(FstreamC * );
	void WriteaStep(FstreamF * );
	vector<double> rd;
	vector<string> CurrentPDB;
	static int    step_c;
	static Real  prec_c,time_c;
	static gmx_bool bOK_c;

public:
	FAtoms():Atoms(), firsttime(true){};
	FAtoms(const int y): Atoms(y), firsttime(true){};
	FAtoms(const Atoms & y): Atoms(y), firsttime(true){};
	FAtoms(const AtomIndex & y): Atoms(y), firsttime(true){};

	virtual ~FAtoms();
	void setrd(vector<double> & rdx) {rd=rdx;};
	double getrd(int n){return rd[n];}
	void pdb(const vector<string> & );
	void initPDB(const vector<string> & x){CurrentPDB=x;}
	Real getTime(){return time_c;}

	friend Fstream & operator+=(Fstream & fin, FAtoms & y){
		if(FstreamC * finC=dynamic_cast<FstreamC *> (&fin))
			y.moveOffset(finC);
		else if(FstreamF * finF=dynamic_cast<FstreamF *> (&fin))
			y.moveOffset(finF);

		return fin;
	}

	friend std::ifstream & operator+=(std::ifstream & fin,FAtoms & y){
		y.moveOffset(fin);
		return fin;
	}

	friend Fstream & operator>>(Fstream & fin, FAtoms & y){
		if(FstreamC * finC=dynamic_cast<FstreamC *> (&fin))
			y.ReadaStep(finC);
		else if(FstreamF * finF=dynamic_cast<FstreamF *> (&fin))
			y.ReadaStep(finF);
		return fin;
	}
	friend Fstream & operator<<(Fstream & fout, FAtoms & y){
		if(FstreamC * foutC=dynamic_cast<FstreamC *> (&fout))
			y.WriteaStep(foutC);
		return fout;
	}

	friend std::ifstream & operator>>(std::ifstream & fin, FAtoms & y){
		y.ReadaStep(fin);
		return fin;
	}

};

#endif /* FATOMS_H_ */
